/*
 * CompanyInfoService.java
 * 
 * Created: Jul 21, 2015
 * 
 * Copyright (c) ExpertPB 2015
 * All information contained herein is, and remains the property of
 * ExpertPB and its suppliers, if any.
 */
package com.emex.app.web.service;

import com.emex.app.shared.data.CompanyInfo;
import com.emex.app.shared.data.CompanyInfoExample;
import com.emex.app.shared.data.Numbers;
import com.emex.app.shared.persistance.CompanyInfoMapper;
import com.emex.app.shared.persistance.NumbersMapper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Sergey
 */
@Service
@Transactional
public class CompanyInfoService {

    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    @Autowired
    private NumbersMapper numbersMapper;

    public CompanyInfo insertCompanyInfo(CompanyInfo record) {
        companyInfoMapper.insert(record);
        return record;
    }

    public CompanyInfo getCompanyInfo() {
        List<CompanyInfo> result = companyInfoMapper.selectByExampleWithBLOBs(null);
        if (null == result || result.isEmpty()) {
            return null;
        }
        return result.get(0);
    }

    public CompanyInfo updateCompanyInfo(CompanyInfo record) {
        companyInfoMapper.updateByPrimaryKeyWithBLOBs(record);
        return record;
    }

    public Numbers insertNumbers(Numbers record) {
        numbersMapper.insert(record);
        return record;
    }

    public Numbers getNumbers() {
        List<Numbers> result = numbersMapper.selectByExample(null);
        if (null == result || result.isEmpty()) {
            return null;
        }
        return result.get(0);
    }

    public Numbers updateNumbers(Numbers record) {
        numbersMapper.updateByPrimaryKey(record);
        return record;
    }
}
